package uit.ce03.game_ninja;

import uit.ce03.game_ninja.database.Database;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Game_HighScore extends Activity{
	TextView tv;
	Button bt_back;
	public Database db;
	Cursor mcursor;
	String chuoi ="HIGHSCORE PLAYER" + "\n";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.highscroce);
		tv = (TextView)findViewById(R.id.textView_highsroce);
		bt_back = (Button)findViewById(R.id.bt_highsroce);
		bt_back.getBackground().setAlpha(50);
		bt_back.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		db = new Database(this);
		try {
			db.open();
			Cursor c = db.getAllRows();
			if (!c.moveToFirst()) {
				db.isertRow("Player", 100);
				db.isertRow("Player", 100);
				db.isertRow("Player", 100);
				db.isertRow("Player", 100);
				db.isertRow("Player", 100);
				db.isertRow("Player", 100);
				db.isertRow("Player", 100);
				db.isertRow("Player", 100);
				db.isertRow("Player", 100);
				
			}
			c.close();
			db.close();
		} catch (SQLiteException e) {
			e.printStackTrace();
		}
		updateList();
		
	
		//;
		
	}
	public void updateList(){
		int i = 0;
		try {
			db.open();
			Cursor c = db.getAllRows();
			if (c.moveToFirst()) {
				do {
					String name = c.getString(c.getColumnIndex(Database.KEY_NAME));
					int math = c.getInt(c.getColumnIndex(Database.KEY_DIEM));
					
					chuoi += name +" - " + math +"\n";
					if (i == 8)
						break;
					else
						i++;
				} while (c.moveToNext());
			}
			c.close();
			db.close();
			tv.setText(chuoi);
		} catch (SQLiteException e) {
			e.printStackTrace();
		}
	}
	
	

}
